package cn.gwm.flink.streaming.dwm.charge.assist.gps;

import cn.gwm.flink.streaming.constant.BaseFields;
import cn.gwm.flink.streaming.constant.VehicleType;
import cn.gwm.flink.streaming.dwm.charge.bean.ChargeArgs;
import cn.gwm.flink.streaming.dwm.charge.util.LastGPSUtil;
import cn.gwm.utils.GpsBean;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;

/**
 * @ClassName RedisGpsMatch
 * @Description 从redis中进行匹配
 * @Author LiangGuang
 * @Date 2023/06/28 15:25
 */
public class RedisGpsMatch extends GpsMatch {
    @Override
    public void match(JSONObject summar, ChargeArgs args) throws Exception {
        if (super.getNext() != null) {
            super.getNext().match(summar, args);
        }
        if (!summar.containsKey(BaseFields.LATITUDE) || BaseFields.defaultVal.equals(summar.getStr(BaseFields.LATITUDE))) {
            JSONObject nowdata = args.getRealNowData();
            GpsBean gpsBean = LastGPSUtil.redisLastGPS(nowdata.getStr(VehicleType.VEHICLE_TYPE), nowdata.getStr(BaseFields.vin), nowdata.getLong(BaseFields.tid));
            if (BeanUtil.isNotEmpty(gpsBean)) {
                summar.set(BaseFields.LATITUDE, gpsBean.getWgLat());
                summar.set(BaseFields.LONGITUDE, gpsBean.getWgLon());
            }

        }
    }
}
